//
//  HttpManager.m
//  RACExample
//
//  Created by 山刘 on 2020/6/3.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "HttpManager.h"

@implementation HttpManager
#pragma mark - init
-(instancetype)initWithBaseURLString:(NSString *)URLString{
    if (self = [super init]) {
        _manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:URLString]];
        _manager.requestSerializer = [AFJSONRequestSerializer serializer];
        _manager.responseSerializer = [AFJSONResponseSerializer serializer];
    }
    return self;
}
/// 普通的网络请求功能
-(void)requestNetworkDataWithUrlString:(NSString*)urlString Params:(NSDictionary*)params completed:(void(^)(id response,NSError * error))completed{
    [self.manager GET:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        completed(responseObject,nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        completed(nil,error);
    }];
}
@end
